package com.smedi.ismedi.inmail.core.port.adapter.restful;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogOrgStaticsExportRequest;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogOrgStaticsPageRequest;
import com.smedi.ismedi.inmail.api.dto.request.LoginLogOrgStaticsPageRequest;
import com.smedi.ismedi.inmail.api.dto.response.LoginLogOrgStaticsResponse;
import com.smedi.ismedi.inmail.api.feign.RemoteLoginLogOrgStaticsFeignApi;
import com.smedi.ismedi.inmail.core.application.command.LoginLogOrgStaticsListCommand;
import com.smedi.ismedi.inmail.core.application.command.LoginLogOrgStaticsPageCommand;
import com.smedi.ismedi.inmail.core.application.command.LoginLogOrgStaticsPageCommand;
import com.smedi.ismedi.inmail.core.application.command.LoginLogUserStaticsListCommand;
import com.smedi.ismedi.inmail.core.application.query.LoginLogOrgStaticsQueryService;
import com.smedi.ismedi.inmail.core.application.service.LoginLogOrgStaticsApplicationService;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.LoginLogOrgStatics;
import com.smedi.ismedi.inmail.core.domain.aggregatemodel.LoginLogUserStatics;
import com.smedi.ismedi.inmail.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 通知公告Controller
 *
 * @author jiangqinxuan
 * @date 2021/07/26
 */
@AllArgsConstructor
@RestController
public class LoginLogOrgStaticsController implements RemoteLoginLogOrgStaticsFeignApi {
    private final LoginLogOrgStaticsQueryService loginLogOrgStaticsQueryService;
    private final LoginLogOrgStaticsApplicationService loginLogOrgStaticsApplicationService;

    private final AdapterConverter adapterConverter;

    @Override
    public ResponseData<PaginationData<LoginLogOrgStaticsResponse>> page(LoginLogOrgStaticsPageRequest loginLogOrgStaticsPageRequest) {
        LoginLogOrgStaticsPageCommand loginLogOrgStaticsPageCommand = adapterConverter.loginLogOrgStaticsPageRequestToLoginLogOrgStaticsPageCommand(loginLogOrgStaticsPageRequest);
        Page<LoginLogOrgStatics> loginLogOrgStaticsPage =  loginLogOrgStaticsQueryService.page(loginLogOrgStaticsPageCommand);
        PaginationData<LoginLogOrgStaticsResponse> loginLogOrgStaticsResponsePaginationData = adapterConverter.loginLogOrgStaticsPageToLoginLogOrgStaticsResponsePaginationData(loginLogOrgStaticsPage);
        return new ResponseData<>().success(loginLogOrgStaticsResponsePaginationData);
    }

    @Override
    public ResponseData<Boolean> statics() {
        loginLogOrgStaticsApplicationService.statics();
        return new ResponseData<>().success(true);
    }

    @Override
    public ResponseData<String> export(LoginLogOrgStaticsExportRequest loginLogOrgStaticsExportRequest) {
        LoginLogOrgStaticsListCommand loginLogOrgStaticsListCommand = adapterConverter.loginLogOrgStaticsExportRequestToLoginLogOrgStaticsListCommand(loginLogOrgStaticsExportRequest);
        List<LoginLogOrgStatics> loginLogOrgStatics = loginLogOrgStaticsQueryService.list(loginLogOrgStaticsListCommand);
        return new ResponseData<>().success(loginLogOrgStaticsApplicationService.export(loginLogOrgStatics));
    }
}
